package com.dzsw.terasoluna.boot.controller;

import lombok.extern.slf4j.Slf4j;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Tag(name = "DemoController", description = "demo controller")
@RestController
@RequestMapping("/d")
public class DemoController {

    @Operation(summary = "first api.", description = "this is a test api.")
    @GetMapping("/exec1")
    public String exec1(@Parameter(name="name") @RequestParam("name") String name) {
        log.info("visitor is {}!", name);
        return "/d/exec1 ok!";
    }

    @GetMapping("/exec2")
    public List<Map<String, Object>> exec2() {
        List<Map<String, Object>> retList = new ArrayList<>();
        for (int i = 0; i < 15; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("name", "laoda_name_" + i);
            retList.add(map);
        }
        return retList;
    }

    @GetMapping("/exec3")
    public Map<String, Object> exec3() {
        Map<String, Object> map = new HashMap<>();
        map.put("name", "藤原佐為");
        return map;
    }
}
